<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html,
        body {
            width: 100%;
            height: 100%;
            position: relative;
        }

        div {
            width: 100px;
            height: 100px;
            background: blue;
            position: absolute;
        }
    </style>
</head>

<body>
    <div></div>
</body>

</html>
<script>
    var div = document.querySelector('div')

    div.onmousedown = function () {

        document.onmousemove = function (e) {
            var e = e || window.event
            div.style.left = e.clientX - div.offsetWidth / 2 + 'px'
            div.style.top = e.clientY - div.offsetHeight / 2 + 'px'
        }
        div.onmouseup = function () {
            document.onmousemove = null;
        }
    }


</script>